]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
StTextureCache: Fix leak of key string
authorColin Walters <walters@verbum.org>
Tue, 24 May 2011 16:51:47 +0000 (12:51 -0400)
committerColin Walters <walters@verbum.org>
Tue, 24 May 2011 17:00:46 +0000 (13:00 -0400)
Also micro-optimize by avoiding another strdup(), instead pass
ownership of the string when we can.

https://bugzilla.gnome.org/show_bug.cgi?id=649508

src/st/st-texture-cache.c

index fba794aafa25aa09c3cd512235aa8d12f4405bdb..24471bcedb3300a6964544ab4fbc8ae013215379 100644 (file)
@@ -1154,7 +1154,6 @@ create_texture_and_ensure_request (StTextureCache        *cache,
     {
       /* Not cached and no pending request, create it */
       *request = g_new0 (AsyncTextureLoadData, 1);
-      (*request)->key = g_strdup (key);
       g_hash_table_insert (cache->priv->outstanding_requests, g_strdup (key), *request);
     }
   else
@@ -1209,9 +1208,10 @@ load_gicon_with_colors (StTextureCache    *cache,
   info = gtk_icon_theme_lookup_by_gicon (theme, icon, size, GTK_ICON_LOOKUP_USE_BUILTIN);
   if (info != NULL)
     {
+      /* Transfer ownership of key */
+      request->key = key;
       /* hardcoded here for now; we should actually blow this away on
        * icon theme changes probably */
-      request->key = g_strdup (key);
       request->policy = ST_TEXTURE_CACHE_POLICY_FOREVER;
       request->icon = g_object_ref (icon);
       request->icon_info = info;
@@ -1227,14 +1227,13 @@ load_gicon_with_colors (StTextureCache    *cache,
        */
        g_slist_foreach (request->textures, (GFunc) g_object_unref, NULL);
        g_slist_free (request->textures);
-       g_free (request->key);
        g_free (request);
        g_hash_table_remove (cache->priv->outstanding_requests, key);
+       g_free (key);
        g_object_unref (texture);
        texture = NULL;
     }
 
-  g_free (key);
   return CLUTTER_ACTOR (texture);
 }